package com.wwwarehouse.contract.release_supply_requirements;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.widget.ListView;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.contract.adapter.LocalPublishAdapter;
import com.wwwarehouse.contract.bean.SelectResourseBean;
import com.wwwarehouse.contract.common.ContractCommon;

import java.util.ArrayList;
import java.util.List;

import contract.wwwarehouse.com.contract.R;

/**
 * @创建者 chenchao.
 * @创建时间 2017/9/25 16:53
 * @描述 ${TODO}
 */

public class LocalPublishResourceListFragmentChild extends BaseFragment {

    private View mView;
    private ListView mListView;
    private List<SelectResourseBean.ListBean> mSelectToCanSeePublishList;
    private List<SelectResourseBean.ListBean> mCurrentList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_local_resourse_list_child, container, false);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }

    private void initView() {
        mListView = findView(mView, R.id.lv_can_see_publish);
    }

    private void initData() {
        mCurrentList = new ArrayList<>();
        mSelectToCanSeePublishList = ContractCommon.getInstance().getSelectToCanSeePublishList();//选中但未发布的集合
        List<SelectResourseBean.ListBean> selectChildList = new ArrayList<>();
        selectChildList.addAll(mSelectToCanSeePublishList);
        Bundle bundleAsk = getArguments();
        if (bundleAsk != null) {
            int page = bundleAsk.getInt("page");

            if (selectChildList.size() > 7 * page) {


                for (int i = 0 + (page - 1) * 7; i < 7 * page; i++) {
                    mCurrentList.add(selectChildList.get(i));
                }

            } else {
                for (int i = 0 + 7 * (page - 1); i < selectChildList.size(); i++) {
                    mCurrentList.add(selectChildList.get(i));
                }
            }


            mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    mListView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    int itemHeight = (mListView.getMeasuredHeight() - mListView.getPaddingTop() - mListView.getPaddingBottom()) / 7;
                    LocalPublishAdapter localPublishAdapter = new LocalPublishAdapter(mActivity, mCurrentList, itemHeight);
                    mListView.setAdapter(localPublishAdapter);

                }
            });
        }


    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof LocalPublishResourceListFragmentChild) {

        }
    }

    @Override
    public void requestDatas() {

    }
}
